requirejs.config({
    baseUrl:"src/js/",
    paths:{
        "jquery":["lib/jquery-3.3.1"],
        "storageTools":["lib/storageTools"],
        "animate":["lib/animate"],
        "jquery.fly.min":["lib/jquery.fly.min"],

             shim:{
                 "animate":{
                     deps:["jquery"]
                 },
                 "jquery.fly.min":{
                     deps: ["jquery"]
                 }

             }
    }
});
require(["jquery","storageTools","animate","jquery.fly.min"],function ($,tools) {
    console.log($);

    //无缝轮播
    $(function () {
        var oUl = document.querySelector('.lunbotu .box #ul');

        var oAll = document.querySelector('.lunbotu');//移入移除


        //1.拿都第一张
        var ocloneLi1 = document.querySelector('.lunbotu>.box>ul>li').cloneNode(true);

        oUl.appendChild(ocloneLi1);//克隆并且追加到最后一张


        //2.动态创建小圆点, -1

        var oLiAll = document.querySelectorAll('.lunbotu .box>ul> li');

        for (var i = 0; i < oLiAll.length - 1; i++) {
            var newLi = document.createElement("li");

            newLi.index = i;

            newLi.onclick = function () {

                autoIndex = dianIndex = this.index-1;

                autoPlay();
            }
            if (i == 0) {
                newLi.className = "current";
            }

            document.querySelector(".lunbotu .box ol").appendChild(newLi)
        }

        var timer = setInterval(autoPlay, 1500);
        //3.自动轮播,
        var autoIndex = 0;
        var dianIndex = 0;

        function autoPlay() {
            autoIndex++;
            if (autoIndex >8) {
                autoIndex = 1;

                oUl.style.left = "0px";
            }

            animate(oUl, -1 * autoIndex * 1210);

            dianIndex++;
            if (dianIndex >7) {
                dianIndex = 0;
            }

            var nextLis = document.querySelectorAll(".lunbotu ol li");


            for (var i = 0; i < nextLis.length; i++) {
                nextLis[i].className = "";
            }
            nextLis[dianIndex].className = "current";

        }


        //4.鼠标移入暂停定时器.

        oAll.onmouseenter = function () {

            clearInterval(timer);
        }


        //5.鼠标移除,开启定时器
        oAll.onmouseleave = function () {
            timer = setInterval(autoPlay, 3000);
        }

    });

    $(function () {
        var closeA = document.querySelector(".popup_main a");
        closeA.onclick = function () {
            this.parentNode.parentNode.style.display = "none";
        }
    });
    //tab栏切换
    $(function () {
        $(".tab-wrapper>.storesame_link>li").on("mouseenter",function () {
            $(this).addClass("currentli").siblings(".tab_li").removeClass("currentli");
            var $index=$(this).index();
            $(".storesame>.storesame_box").eq($index).addClass("currentbox").siblings(".storesame_box").removeClass("currentbox");
        })
        // var allLi = document.querySelectorAll(".storesame_link>li");
        // for (var i = 0; i < allLi.length; i++) {
        //     allLi[i].index = i;//记录索引号
        //     allLi[i].onmouseenter = function () {
        //         for (var i = 0; i < allLi.length; i++) {
        //
        //             allLi[i].className = "";
        //         }
        //         this.className = "currentli";//给自己加样式
        //     }
        // }


    });
    $(function () {
        $("#back-top").on("click", function () {
            $("html,body").animate({scrollTop: 0}, 200);
        })
    });
    $(function () {
        $(".footer").load('./footer.html',function () {
            //console.log("底部加载完成后执行");
        })
    });
    $(function () {
        var offset = $("#end").offset();  //结束的地方的元素
        $(".storesame-right-top ul>.top").on("click","#jrgwc",function(event){   //是$(".addcar")这个元素点击促发的 开始动画的位置就是这个元素的位置为起点

            var jrgwc = $(this);
            console.log(jrgwc);
            var img = jrgwc.parent().find('img').attr('src');
            var flyer = $('<img class="u-flyer" src="'+img+'">');
            //飞
            flyer.fly({
                //起点
                start: {
                    left: event.pageX,
                    top: event.pageY
                },
                //终点
                end: {
                    left: offset.left,
                    top: offset.top,
                    width: 0,
                    height: 0
                },
                //到达终点后调用的
                onEnd: function(){
                    console.log("到达终点");
                    $("#msg").show().animate({width: '250px'}, 200).fadeOut(1000);
                }
            });

        });
    });
    $(function () {
        var jsonStr=tools.get("login1");
        console.log(jsonStr);
        if(jsonStr!=null){
            $("#h4").show();
            $("#loginb").text('注销');
            $.ajax({
                url:"http://127.0.0.1:80/diwu/sever/goods.php",
                dataType:"json"


            }).done(function (res) {
              res.forEach((el,index)=>{


                  const strHtml=`
                   
          
                        <a id="jrgwc" data-info='${JSON.stringify(el)}'>加入购物车</a>
                  
                `;
                  $(".storesame-right-top ul>.top").append(strHtml);

                  //console.log(el);


              });
                $(".storesame-right-top ul>.top").on("click","#jrgwc",function() {
                   // console.log(this);
                    console.log($(this).data("info"));
                })

            })
        }
       var userInfo=JSON.parse(jsonStr||"{}");

        $("#userinfor").text(userInfo.uname);
    })
})